package com.jj.spb.spring_boot_mybatis.repository;

import com.jj.spb.spring_boot_mybatis.entity.Student;
import org.apache.ibatis.annotations.Param;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface StudentRepository extends JpaRepository<Student,Integer> {

    Student findByStudyNum(int studyNum);

    @Query(nativeQuery = true,value = "SELECT COUNT(*) from student WHERE studyNum = #studyNum")
    int existStudent(@Param("studyNum") int studyNum);

    @Query(nativeQuery = true,value = "SELECT id from student WHERE studyNum = ?1")
    Optional<Integer> findIdByStudyNum(int studyNum);
}
